package com.cooksys.film_rental.bo.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.UserBo;
import com.cooksys.film_rental.dao.UserDao;
import com.cooksys.film_rental.model.Customer;
import com.cooksys.film_rental.model.User;

@Service("UserBo")
public class UserBoImpl implements UserBo {

	@Autowired(required = true)
	UserDao userDao;

	@Override
	public User getUserByUserId(String userId) {
		return this.userDao.getUserByUserId(userId);
	}

	@Override
	public User getUserByCustomerId(Short customerId) {
		return this.userDao.getUserByCustomerId(customerId);
	}

	@Override
	public User getUserByCustomerId(String customerId) {
		try {

			Short customerIdAsShort = Short.valueOf(customerId);
			return this.getUserByCustomerId(customerIdAsShort);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Short value for customerId from string: "
							+ customerId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}
	}

	@Override
	public User getUserByCustomer(Customer customer) {
		return this.userDao.getUserByCustomer(customer);
	}

	@Override
	public User save(User user) {
		return this.userDao.save(user);
	}

}
